package com.partner.boot.service.impl;


import com.partner.boot.entity.Comment;
import com.partner.boot.entity.CommentQuery;
import com.partner.boot.entity.Pagination;
import com.partner.boot.mapper.CommentMapper;
import com.partner.boot.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class CommentServiceImpl implements ICommentService {
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public Pagination selectComment(Integer page, Integer pageSize, CommentQuery query) {
//        System.out.println(query.getUserId());
        int total=commentMapper.countComment(query);
        Pagination<Comment> pagination=new Pagination(page,pageSize,total);
        //获取当前页的记录集合
        pagination.setRecords(commentMapper.selectComment(pagination.getOffset(),pagination.getPageSize(),query));
        return pagination;
    }

    @Override
    public void addComment(Comment comment) {
        comment.setCreateTime(new Date());
        comment.setDeleted(0);
        commentMapper.addComment(comment);
    }

    @Override
    public void updateComment(Comment comment) {
        comment.setUpdateTime(new Date());
        commentMapper.updateComment(comment);
    }

    @Override
    public void deleteComment(Integer id) {
        commentMapper.deleteComment(id);
    }

    @Override
    public void deletesComment(Integer[] ids) {
        commentMapper.deletesComment(ids);
    }
}
